<link rel="stylesheet" type="text/css" href="{{URL::asset('public_css/base.css') }}" />
<link rel="stylesheet" type="text/css" href="{{URL::asset('handan/css/footer.css') }}"/>
<link rel="stylesheet" type="text/css" href="{{URL::asset('recommend/css/recommendhistory.css') }}">
@include('new.newheader')
<div class="recommendhistory">
    <div class="introduce">
        <div class="left">
            <div class="photo">
                <img src="{{$userInfo->photo}}" alt="">
            </div>
            <div class="name">
                <div>
                    <span>{{$userInfo->nickname}}</span>
                    <span><img src="{{ URL::asset('recommend/images/recommendcenter/v.png') }}" alt=""></span>
                </div>
                <div>
                    <span>
                        <img src="{{ URL::asset('recommend/images/recommendcenter/crown.png') }}" alt="">
                    </span>
                    <span>数据分析师</span>
                </div>
                <div class="addr">
                    <span>
                        <img src="{{ URL::asset('recommend/images/recommendcenter/addr.png') }}" alt="">
                    </span>
                    <span>{{$userInfo->province}} {{ $userInfo->city}} {{ $userInfo->country}}</span>
                </div>
            </div>
            <div class="brief">
                <div class="title">简介:&nbsp;&nbsp;</div>
                <div class="cont">{{$userInfo->intro}}</div>
            </div>
        </div>
        <div class="right">
            <div>
                <p>订阅人数</p>
                <p>{{$userInfo->followCount}}</p>
            </div>
            <div class="line"></div>
            <div>
                <p>总赞数</p>
                <p>{{$userInfo->allUpvotes}}</p>
            </div>
            <div class="line"></div>
            <div>
                <p>推荐条数</p>
                <p>{{$userInfo->count}}</p>
            </div>
        </div>
    </div>
    <!-- 发布历史详情 -->
    @if(count($RecommandList))
        @foreach($RecommandList as $val)
            <div class="history">
                <div class="intro clearfloat">
                    <div class="photo">
                        <img src="{{ $val['userPhoto'] }}" alt="">
                    </div>
                    <div class="name">
                        <span>{{ $val['nickname'] }}</span>
                        <span class="vip"><img src="{{ URL::asset('recommend/images/recommendcenter/v.png') }}" alt=""></span>
                        <p class="brief">
                            <span><img src="{{ URL::asset('recommend/images/recommendcenter/crown.png') }}" alt=""></span>
                            <span>数据分析师</span>
                        </p>
                    </div>
                    @if($id == Session::get('eai')['id'])
                        <!-- 删除按钮 -->
                        <div class="btn" onclick="del({{$val->listid}},this);">
                            <span class="del">
                                <img src="{{ URL::asset('recommend/images/recommendhistory/del.png') }}" alt="">
                            </span>
                            <span>删除</span>
                        </div>
                        <!-- 编辑按钮 -->
                        <div class="btn edit_btn" onclick="javascript:window.location.href='{{url("/authenticate?id=recomm&listid=")}}{{$val->listid}}'">
                            <span class="edit">
                                <img src="{{ URL::asset('recommend/images/recommendhistory/edit.png') }}" alt="">
                            </span>
                            <span>编辑</span>
                        </div>
                    @endif
                </div>
                <div class="detail">
                    <div class="desc">
                        {{$val['content']}}
                    </div>
                    <div class="chart">
                        @foreach($val['photo'] as $v)
                            <span><img src="{{$v}}" alt=""></span>
                        @endforeach
                    </div>
                    <!-- 本周推荐 -->
                    <div class="week clearfloat">
                        <p>本周推荐</p>
                        <ul>
                            @foreach($val['analystInfo'] as $k)
                            <li>
                                <div>
                                    <p class="photo">
                                        <img src="{{ $k->photo }}" alt="">
                                        <span><img src="{{ URL::asset('recommend/images/recommendcenter/vip@greatmaster.png') }}" alt=""></span>
                                    </p>
                                </div>
                                <div>
                                    <p class="name">{{ $k->username }}</p>
                                    <p class="zhiwei">行情分析师</p>
                                    <p class="btn">
                                        <span class="icon"><img src="{{ URL::asset('recommend/images/recommendhistory/add.png') }}" alt=""></span>
                                        <span>@if($k->direction == 0) 正向 @else 反向 @endif</span>
                                    </p>
                                </div>
                            </li>
                            @endforeach
                        </ul>
                    </div>
                    <!-- 发布时间 -->
                    <div class="releaseTime clearfloat">
                        <div class="time"><?php echo date('Y-m-d H:i:s',$val['time']); ?></div>
                        <div class="fabulous">
                            <!-- <span>订阅人数</span>
                            <span>20</span>&nbsp;&nbsp;-->
                            <span>
                                <span class="img" @if($id != Session::get('eai')['id']) onclick="upvotes({{$val->listid}},this)" @endif>
                                    <img src="{{ URL::asset('recommend/images/recommendcenter/fabulous.png') }}" alt="">
                                </span>
                                <span class="num">{{$val['upvotes']}}</span>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        @endforeach
        <!-- 分页 -->
        {{ $RecommandList->links() }} 
    @else
        <div class="warmTips">您还没有发布内容呢</div>
    @endif 
    <!-- 删除提示弹窗 -->
    <div class="tip_popup">
        <div class="mask"></div>
        <div class="popup">
            <div class="title">
                <div class="left">删除确认</div>
                <div class="right" onclick="closePopup();"><img src="{{ URL::asset('recommend/images/clonse.png') }}" alt=""></div>
            </div>
            <div class="cont">
                <span><img src="{{ URL::asset('recommend/images/recommendhistory/tip.png') }}" alt=""></span>
                <span>删除发布后不能恢复, 确定要删除吗 ?</span>
            </div>
            <div class="bot">
                <div>
                    <span onclick="cancelDel();">取消</span>
                    <span onclick="sureDel();">删除</span>
                </div>
            </div>
        </div>
    </div>
    <div class="replace"></div>
</div>
<!-- 内容距底部撑块 -->
<div style="width: 100%;height: 126px;"></div>
<!-- 底部 -->
@include('layout.footer')
<script src="{{URL::asset('public_js/jquery-3.2.1.min.js')}}"></script>
<script src="{{ URL::asset('recommend/js/recommendlist.js')}} "></script>
<script>
    var upvotesurl = "{{url('/upvotes')}}";//点赞地址
    var recid  = 0;//删除推荐信息id
    var recobj = '';//删除推荐对象
    // 删除弹窗
    function del(id,obj) {
        recobj = obj;
        recid = id;
        $('.tip_popup').show();
        var top = $(document).scrollTop();
        $(document).on('scroll.unable',function (e) {
            $(document).scrollTop(top);
        })
    }
    // ×关闭
    function closePopup() {
        $('.tip_popup').hide();
        $(document).unbind("scroll.unable");
    }
    // 取消关闭
    function cancelDel() {
        $('.tip_popup').hide();
        $(document).unbind("scroll.unable");
    }
    // 确认删除
    function sureDel() {
        $.ajax({
            url: '{{url("/delrecid")}}',
            type: 'post',
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
            data: {'id':recid},
            success: function(res) {
                if(res.status == 1){
                    $('.tip_popup').hide();
                    $(recobj).parents('.history').remove();
                    $(document).unbind("scroll.unable");
                }else if(res.status == 2){
                    layer.msg("请先登录");
                }else{
                    layer.msg("删除失败");
                }

            }
        })
    }
    function enable_scroll() {
        if (window.removeEventListener) {
            window.removeEventListener('DOMMouseScroll', wheel, false);
        }
        window.onmousewheel = document.onmousewheel = document.onkeydown = null; 
    }
    // 展开收起
    (function($){
        $.fn.moreText = function(options){
            var defaults = {
                maxLength:50,
                mainCell:".desc",
                openBtn:'展开',
                closeBtn:'收起'
            }
            return this.each(function() {
                var _this = $(this);
                
                var opts = $.extend({},defaults,options);
                var maxLength = opts.maxLength;
                var TextBox = $(opts.mainCell,_this);
                var openBtn = opts.openBtn;
                var closeBtn = opts.closeBtn;
                
                var countText = TextBox.html();
                var newHtml = '';
                if(countText.length > maxLength){
                    newHtml = countText.substring(0,maxLength)+'...<span class="more">'+openBtn+'</span>';
                }else{
                    newHtml = countText;
                }
                TextBox.html(newHtml);
                TextBox.on("click",".more",function(){
                    if($(this).text()==openBtn){
                        TextBox.html(countText+' <span class="more">'+closeBtn+'</span>');
                    }else{
                        TextBox.html(newHtml);
                    }
                })
            })
        }
    })(jQuery);
    $(function(){
        $(".detail").moreText({
            maxLength: 100, //默认最大显示字数，超过...
            mainCell: '.desc' //文字容器
        });
    })
</script>
